package com.sui.bigdata.sml.web.repository.mapper;

import com.sui.bigdata.sml.web.repository.model.Experiment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author songhaicheng
 * @date 2019/11/5 10:00
 * @description
 * @reviewer
 */
@Repository
public interface ExperimentMapper {

    @Insert("insert into experiment(name,user_id,description,project_id) values(#{name},#{userId},#{description},#{projectId})")
    @Options(useGeneratedKeys = true)
    int insert(Experiment experiment);

    @Select("select * from experiment where id=#{id}")
    Experiment get(Long id);

    @Update("<script>" +
            "update experiment set name=#{name},description=#{description},project_id=#{projectId}" +
            "<if test='delete!=null'>" +
            ",`delete`=#{delete}" +
            "</if>" +
            " where id=#{id}" +
            "</script>")
    int update(Experiment experiment);

    @Select("select * from experiment where project_id=#{projectId} and `delete`=#{delete}")
    List<Experiment> listByProjectId(@Param("projectId") Long projectId, @Param("delete") Boolean delete);

}
